package com.zxc.service;


import java.text.SimpleDateFormat;
import java.util.Date;

import org.apache.log4j.Logger;
import org.eclipse.swt.widgets.Text;

public class ConsoleService {
	private static volatile ConsoleService instance;
	private static Text text;
	private static final Logger log = Logger.getLogger(ConsoleService.class);
	
	private ConsoleService(){
		
	}
	
	public static void createInstance(Text texts){
		if(instance == null){
			synchronized(ConsoleService.class){
				if(instance == null){
					instance = new ConsoleService();
				}				
			}
		}
		
		if(text == null){
			synchronized(ConsoleService.class){
				if(text == null){
					text = texts;
				}				
			}
		}
	}
	
	public static synchronized void receiveMessage(String message){
		SimpleDateFormat format = new SimpleDateFormat("yyyy.MM.dd HH:mm:ss");
		log.info(message);
		text.append("["+format.format(new Date())+"]  " + message + "\n");
	}
}
